<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tk_GetColormap manual page - Tk Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk C API</a> <small>&gt;</small> GetClrmap</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<DL>
<DD><A HREF="GetClrmap.htm#M2" NAME="L272">NAME</A>
<DL><DD>Tk_GetColormap, Tk_PreserveColormap, Tk_FreeColormap &mdash; allocate and free colormaps</DD></DL>
<DD><A HREF="GetClrmap.htm#M3" NAME="L273">SYNOPSIS</A>
<DL>
<DD><B>#include &lt;tk.h&gt;</B>
<DD>Colormap
<DD><B>Tk_GetColormap(</B><I>interp, tkwin, string</I><B>)</B>
<DD><B>Tk_PreserveColormap(</B><I>display, colormap</I><B>)</B>
<DD><B>Tk_FreeColormap(</B><I>display, colormap</I><B>)</B>
</DL>
<DD><A HREF="GetClrmap.htm#M4" NAME="L274">ARGUMENTS</A>
<DL class="arguments">
</DL>
<DD><A HREF="GetClrmap.htm#M5" NAME="L275">DESCRIPTION</A>
<DD><A HREF="GetClrmap.htm#M6" NAME="L276">KEYWORDS</A>
</DL>
<H3><A NAME="M2">NAME</A></H3>
Tk_GetColormap, Tk_PreserveColormap, Tk_FreeColormap &mdash; allocate and free colormaps
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tk.h&gt;</B><BR>
Colormap<BR>
<B>Tk_GetColormap(</B><I>interp, tkwin, string</I><B>)</B><BR>
<B>Tk_PreserveColormap(</B><I>display, colormap</I><B>)</B><BR>
<B>Tk_FreeColormap(</B><I>display, colormap</I><B>)</B><BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT><A HREF="../TclLib/Interp.htm">Tcl_Interp</A> <B>*interp</B> (in)<DD>
Interpreter to use for error reporting.
<P><DT><A HREF="../TkLib/WindowId.htm">Tk_Window</A> <B>tkwin</B> (in)<DD>
Token for window in which colormap will be used.
<P><DT>const char <B>*string</B> (in)<DD>
Selects a colormap:  either <B>new</B> or the name of a window
with the same screen and visual as <I>tkwin</I>.
<P><DT>Display <B>*display</B> (in)<DD>
Display for which <I>colormap</I> was allocated.
<P><DT>Colormap <B>colormap</B> (in)<DD>
Colormap to free or preserve;  must have been returned by a previous
call to <B>Tk_GetColormap</B> or <B><A HREF="../TkLib/GetVisual.htm">Tk_GetVisual</A></B>.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
These procedures are used to manage colormaps.
<B>Tk_GetColormap</B> returns a colormap suitable for use in <I>tkwin</I>.
If its <I>string</I> argument is <B>new</B> then a new colormap is
created;  otherwise <I>string</I> must be the name of another window
with the same screen and visual as <I>tkwin</I>, and the colormap from that
window is returned.
If <I>string</I> does not make sense, or if it refers to a window on
a different screen from <I>tkwin</I> or with
a different visual than <I>tkwin</I>, then <B>Tk_GetColormap</B> returns
<B>None</B> and leaves an error message in <I>interp</I>'s result.
<P>
<B>Tk_PreserveColormap</B> increases the internal reference count for a
colormap previously returned by <B>Tk_GetColormap</B>, which allows the
colormap to be stored in several locations without knowing which order
they will be released.
<P>
<B>Tk_FreeColormap</B> should be called when a colormap returned by
<B>Tk_GetColormap</B> is no longer needed.
Tk maintains a reference count for each colormap returned by
<B>Tk_GetColormap</B>, so there should eventually be one call to
<B>Tk_FreeColormap</B> for each call to <B>Tk_GetColormap</B> and each
call to <B>Tk_PreserveColormap</B>.
When a colormap's reference count becomes zero, Tk releases the
X colormap.
<P>
<B><A HREF="../TkLib/GetVisual.htm">Tk_GetVisual</A></B> and <B>Tk_GetColormap</B> work together, in that
a new colormap created by <B><A HREF="../TkLib/GetVisual.htm">Tk_GetVisual</A></B> may later be returned
by <B>Tk_GetColormap</B>.
The reference counting mechanism for colormaps includes both procedures,
so callers of <B><A HREF="../TkLib/GetVisual.htm">Tk_GetVisual</A></B> must also call <B>Tk_FreeColormap</B>
to release the colormap.
If <B>Tk_GetColormap</B> is called with a <I>string</I> value of
<B>new</B> then the resulting colormap will never
be returned by <B><A HREF="../TkLib/GetVisual.htm">Tk_GetVisual</A></B>;  however, it can be used in other
windows by calling <B>Tk_GetColormap</B> with the original window's
name as <I>string</I>.
<H3><A NAME="M6">KEYWORDS</A></H3>
<A href="../Keywords/C.htm#colormap">colormap</A>, <A href="../Keywords/V.htm#visual">visual</A>
<div class="copy">Copyright &copy; 1994 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
